<template>
	<view class="content">
		<view style="margin-top:50%">
			<h3 style="display: flex;margin:20rpx 0;">
				<view>姓名：</view>
				<input style="border: 1px solid;text-align: center;width:120rpx;" type="text" v-model="name" />
			</h3>
			<button type="primary" @click="register" >人脸注册</button>
			
			<h3 style="display: flex;margin:20rpx 0;">
				<view>人脸最小得分(通过分)：</view>
				<input style="border: 1px solid;text-align: center;width:120rpx;" type="text" v-model="score" />
			</h3>
			<button type="primary" @click="go" >人脸识别</button>
			<h3 v-show="isResult" style="margin-top:20rpx;">人脸识别结果：{{ faceResult }}</h3>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name:'',
				score:'80',
				faceResult:'',
				isResult:false
			}
		},
		onLoad() {

		},
		methods: {
			register(){
				if(this.name === ''){
					uni.showToast({
						title:'请输入名称！',
						icon:'error'
					})
					return
				}
				uni.navigateTo({
					url:`../faceRec/faceRec?method=add&name=${this.name}`,
					success: function(res) {
						res.eventChannel.on('refreshopts', (d) => {
							res.eventChannel.off('refreshopts');
							this.name = ''
						})
					}
				})
			},
			go(){
				this.isResult = false
				const that = this
				uni.navigateTo({
					url:`../faceRec/faceRec?method=search&score=${this.score}`,
					success: function(res) {
						res.eventChannel.on('refreshopts', (d) => {
							res.eventChannel.off('refreshopts');
							that.faceResult = d
							that.isResult = true
						})
					}
				})
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
